﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;

namespace Bluebunnie
{
    /// <summary>
    /// Interaction logic for SqlExecutor.xaml
    /// </summary>
    public partial class SqlExecutor : Window
    {
        public SqlExecutor()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=project");
            MySqlCommand cmd = new MySqlCommand(txtsql.Text, con);

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();

                MessageBox.Show("Sukses eksekusi query.", "Sukses", MessageBoxButton.OK, MessageBoxImage.Information);

                txtsql.Text = string.Empty;

            }
            catch (Exception ex)
            {
                MessageBox.Show("Gagal eksekusi query.\n\nAlasan:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            finally
            {
                if (con.State != System.Data.ConnectionState.Closed)
                    con.Close();
            }
        }
    }
}
